package KEY;

import org.junit.jupiter.api.Test;

/**
 * @Author: Siantar
 * @Date: 2023-11-18-22:44
 * @Description: 1.0
 */
public class Binary {
    public int binarySearch(int[] nums, int target) {
        int left = 0, right = nums.length;
        while (left < right) {
            int mid = left + ((right - left) >> 1);
            if (nums[mid] < target) {
                left = mid + 1;
            } else if (nums[mid] > target) {
                right = mid - 1;
            } else {
                return mid;
            }
        }
        return -1;
    }

    public int lowerSearch(int[] nums, int target) {
        int left = 0, right = nums.length;
        while (left <= right) {
            int mid = left + ((right - left) >> 1);
            if (nums[mid] < target) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return left;
    }

    @Test
    public void test() {
        int[] nums = new int[]{};
        System.out.println(binarySearch(nums, 3));
    }
}
